
var https = require('https');  
var qs = require('querystring');  
const tcb = require("@cloudbase/node-sdk");
var { request } = require('../utils/index')
const app = tcb.init();
class XcxCtl {
    static async list(ctx) {
      ctx.body = 'hello world'
    }   
	static async getQrCode(ctx){
		const res =await request(`https://7879-xyf-kk-3gg39quy4654bec0-1305555206.tcb.qcloud.la/json/token.json?time=${new Date().getTime()}`)
		const token = res.access_token
		if(token){
			const params = {
				path:'pages/select_shop/index'
			}
			const qrCode = request(`https://api.weixin.qq.com/cgi-bin/wxaapp/createwxaqrcode?access_token=${token}`,'post',params)
			if(qrCode.errcode==0){
				app
				.uploadFile({
					cloudPath: "image/ceshi.png",
					fileContent: qrCode.buffer
				})
				.then((res) => {
					app.getTempFileURL({
						fileList: [res.fileID]
					}).then(r => {
						ctx.body = {...qrCode,code:0,urlr:r}
					})
					// 返回文件 ID
				});
				
			}else{
				ctx.body = {
					code:500,
					message:qrCode.errmsg
				}
			}
		}
		
	}
 
}
  
module.exports= XcxCtl;
  